﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum SizeType
{
    Height,
    Weight,
    All,
    Money,
    Edu,
}
public class Multipler : Gate
{
    public int addValue;
    public int multiValue;
    
    public SizeType type = SizeType.Height;

    private Vector3 m_originScale;
    protected override void Start()
    {
        base.Start();
        
        m_originScale = transform.localScale;
    }

    // Start is called before the first frame update
    public override void UpdateUI()
    {
        bool up = true;
        
        if (contentText)
        {
            if (this.addValue > 0)
            {
                this.contentText.text = "+" + addValue;
                up = true;
            }
            else if (this.addValue < 0)
            {
                this.contentText.text = addValue + "";
                up = false;
            }
            else if (multiValue > 0)
            {
                this.contentText.text = "x" + multiValue;
                up = true;
            }
            else if (multiValue < 0)
            {
                this.contentText.text = "➗" + Mathf.Abs((1 / multiValue));
                up = false;
            }
        }

        if (titleText)
        {
            if (type == SizeType.Height)
            {
                if (up)
                {
                    titleText.text = "+ Height";
                }
                else
                {
                    titleText.text = "- Height";
                }
            }
            else if (type == SizeType.Weight)
            {
                if (up)
                {
                    titleText.text = "+ Weight";
                }
                else
                {
                    titleText.text = "- Weight";
                }
            }
            else if (type == SizeType.Money)
            {
                if (up)
                {
                    titleText.text = "+ $";
                }
                else
                {
                    titleText.text = "- $";
                }
            } 
            else if (type == SizeType.Edu)
            {
                if (up)
                {
                    titleText.text = "+ Score";
                }
                else
                {
                    titleText.text = "- Score";
                }
            }
            else if (type == SizeType.All)
            {
                titleText.text = "Size";
            }
        }

        if (bg && titleBG)
        {
            if (up)
            {
                this.bg.sharedMaterial = this.blueBGMat;
                this.titleBG.sharedMaterial = this.blueTitleBGMat;
            }
            else
            {
                this.bg.sharedMaterial = this.redBGMat;
                this.titleBG.sharedMaterial = this.redTitleBGMat;
            }
        }
    }

    void OnTriggerEnter(Collider other)
    {
        if (!gameObject.activeInHierarchy) return;
        
        if (other.TryGetComponent(out Player player))
        {
            if (player)
            {
                OnTriggerPlayer(player);
            }
        }
    }

    void OnTriggerPlayer(Player player)
    {
        float add = this.addValue;// / 100f;

        if (this.type == SizeType.Height)
        {
            if (this.addValue > 0 || this.addValue < 0)
            {
                player.AddHeight(add);
            }
        }
        else if (this.type == SizeType.Weight)
        {
            if (this.addValue > 0 || this.addValue < 0)
            {
                player.AddWeight(add);
            }
        }
        else if (this.type == SizeType.Money)
        {
            if (this.addValue > 0 || this.addValue < 0)
            {
                player.AddIncome((int)add);
            }
        } 
        else if (this.type == SizeType.Edu)
        {
            if (this.addValue > 0 || this.addValue < 0)
            {
                player.AddEduScore(add);
            }
        }
        if (transform.parent.GetComponent<GatesParent>())
            transform.parent.gameObject.SetActive(false);
        else
            gameObject.SetActive(false);
    }
    
}
